/*
 * A simple ToDo Manager
 *
 * Copyright (c) 2011 Nosheen Zaza, Manuel Rebollo, Seyedsaeid Mahpeikar and
 * Wo Ke
 *
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 * THE SOFTWARE.
 */

package todomanager.ui.dialogs;

import java.awt.BorderLayout;
import javax.swing.BorderFactory;
import javax.swing.BoxLayout;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.UIManager;
import todomanager.model.TaskManager;
import todomanager.ui.ActionControl;
import todomanager.ui.listview.TaskDisplayList;

/**
 * Shows a dialog box that contains undone tasks of today. If there are
 * no tasks to be done, it shows a suitable message informing the user about it.
 * 
 * @author
 * Nosheen Zaza
 */
public class TasksTodayDialog extends JDialog {

    private JLabel todayTasksLabel;
    private JLabel noTasksLabel;
    private TaskDisplayList taskDisplayList;
    private JScrollPane taskScroll;
    private JPanel contentPanel;

    /**
     * Creates and initializes an instance.
     */
    public TasksTodayDialog() {
        todayTasksLabel = new JLabel(
                ActionControl.getInstance().getStringsBundle().getString(
                "TodaysTasks"));
        todayTasksLabel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

        noTasksLabel = new JLabel(
                ActionControl.getInstance(
                ).getStringsBundle().getString("noTasksToday"));
        noTasksLabel.setFont(UIManager.getFont("Font.Dialog-Plain-12"));
        noTasksLabel.setBorder(BorderFactory.createEmptyBorder(10, 10, 0, 0));

        taskDisplayList = new TaskDisplayList(
                TaskManager.getInstance().getTaskList());
        
        taskScroll = new JScrollPane(taskDisplayList);
        taskScroll.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));

        contentPanel = new JPanel();
        contentPanel.setLayout(new BoxLayout(contentPanel, BoxLayout.PAGE_AXIS));
        contentPanel.add(taskScroll);

        
        setLayout(new BorderLayout());
        add(todayTasksLabel, BorderLayout.PAGE_START);
        add(contentPanel, BorderLayout.CENTER);
        
        setTitle(ActionControl.getInstance().getStringsBundle().getString("TodaysTasks"));
        setSize(300, 200);
        setLocationRelativeTo(ActionControl.getInstance().getMainWindow());
        setAlwaysOnTop(true);
    }

    /**
     * Returns a {@code TaskDisplayList} of tasks to be done today. 
     * @return taskDisplayList
     */
    public TaskDisplayList getTaskDisplayList() {
        return taskDisplayList;
    }

    /**
     * Sets this dialog visible or invisible, in addition to that, if the task
     * list is empty, it shows a suitable message instead of an empty list.
     * 
     * @param b a boolean indicated whether to show this dialog box.
     */
    @Override
    public void setVisible(boolean b) {
        super.setVisible(b);
        if(taskDisplayList.getModel().getSize() == 0) {
            contentPanel.remove(taskScroll);
            contentPanel.add(noTasksLabel);
        }
        else {
            contentPanel.remove(noTasksLabel);
            contentPanel.add(taskScroll);
        }
    }
}
